import org.junit.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 * User: 5
 * Date: 16-12-15
 * Time: 上午10:08
 * To change this template use File | Settings | File Templates.
 */
public class ThreadPool {


    @Test
    public void test1() throws InterruptedException {
        ExecutorService executor = Executors.newFixedThreadPool(25);
        NumberPlusPlus p = new NumberPlusPlus();
        for (int i = 0; i < 1000; i++) {
            executor.execute(p);
        }
        executor.shutdown();  //发出关闭线程池信号，拒绝提交任务。，未完成任务会继续完成
        Thread.sleep(6000);
        System.out.println(p.i);
    }

}


class NumberPlusPlus implements Runnable {
    public  int i = 0;


    @Override
    public void run() {
        pp();
    }

    public synchronized void pp() {
        System.out.println("线程：" + Thread.currentThread().getName() );
        ++i;
    }
}